package com.excellence.controller;

import com.excellence.datamodel.Result;
import com.excellence.pojo.News;
import com.excellence.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 沈秉璋
 * @ClassName NewsController
 * @Description TODO
 * @date 2024/4/8 11:40
 * @Version 1.0
 */
//@Controller
//@ResponseBody
@RestController
@RequestMapping("/api/news")
public class NewsController {
    @Autowired
    private NewsService newsService;

    @PutMapping("/deleteByKey")
    Result deleteByKey(Long id){
        int res = newsService.deleteByKey(id);
        return Result.success(res);
    }

    @DeleteMapping("/deleteByPrimaryKey")
    Result deleteByPrimaryKey(Long id){
        int res = newsService.deleteByPrimaryKey(id);
        return Result.success(res);
    }
    @PostMapping("/insert")
    Result insert(News record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = newsService.insert(record, files);
        return Result.success(res);
    }

    @PostMapping("/insertSelective")
    Result insertSelective(News record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = newsService.insertSelective(record, files);
        return Result.success(res);
    }

    @GetMapping("/selectByNewsType")
    Result selectByNewsType(String newsType){
        List<News> res = newsService.selectByNewsType(newsType);
        System.out.println(res);
        return Result.success(res);
    }

    @GetMapping("/selectAll")
    Result selectAll(){
        List<News> res = newsService.selectAll();
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKeySelective")
    Result updateByPrimaryKeySelective(News record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = newsService.updateByPrimaryKeySelective(record, files);
        return Result.success(res);
    }

    @PutMapping("/updateByPrimaryKey")
    Result updateByPrimaryKey(News record, @RequestParam(value = "files",required = false) List<MultipartFile> files){
        int res = newsService.updateByPrimaryKey(record, files);
        return Result.success(res);
    }
}
